/*
 * ArCoLIVEApplication.java
 *
 * Created on 11 de Outubro de 2005, 11:17
 */

package br.ufal.tci.nexos.arcolive.tests;
import java.io.IOException;

import javax.media.Format;
import javax.media.MediaLocator;
import javax.media.format.VideoFormat;
import javax.media.protocol.ContentDescriptor;
import javax.media.protocol.DataSource;
import javax.media.protocol.FileTypeDescriptor;
import javax.media.protocol.PushBufferStream;

import sun.awt.image.ImageDecoder;

import br.ufal.tci.nexos.arcolive.beans.CannotCaptureScreenException;
import br.ufal.tci.nexos.arcolive.beans.MediaRecorder;
import br.ufal.tci.nexos.arcolive.beans.NetworkPlayer;
import br.ufal.tci.nexos.arcolive.beans.PlayerInternalFrame;
import br.ufal.tci.nexos.arcolive.beans.CannotPlayStreamException;
import br.ufal.tci.nexos.arcolive.beans.CannotMediaRecordException;
import br.ufal.tci.nexos.arcolive.beans.CannotStopRecorderException;
import br.ufal.tci.nexos.arcolive.beans.ScreenGrabber;



/**
* This code was generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* *************************************
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED
* for this machine, so Jigloo or this code cannot be used legally
* for any corporate or commercial purpose.
* *************************************
*/
/**
 *
 * @author  Felipe
 */
public class ArCoLIVEApplication extends javax.swing.JFrame {
 
	private br.ufal.tci.nexos.arcolive.beans.PlayerInternalFrame arCoLIVEPlayerInternalFrame1;
    private br.ufal.tci.nexos.arcolive.beans.MediaRecorder arCoLIVERecordMedia1;
    
	
    /** Creates new form ArCoLIVEApplication */
    public ArCoLIVEApplication() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        arCoLIVERecordMedia1 = new br.ufal.tci.nexos.arcolive.beans.MediaRecorder();
        arCoLIVEPlayerInternalFrame1 = new br.ufal.tci.nexos.arcolive.beans.PlayerInternalFrame();

        getContentPane().setLayout(null);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().add(arCoLIVEPlayerInternalFrame1);
        arCoLIVEPlayerInternalFrame1.setBounds(11, 8, 270, 180);

        pack();
        this.setSize(293, 158);
    }
    // </editor-fold>//GEN-END:initComponents
    
    /*public void handle() {
        arCoLIVENetworkPlayerInternalFrame1.handleStream();
    }*/
    
    public void play() {
    	NetworkPlayer np = new NetworkPlayer();
    	ScreenGrabber imageToMovie = new ScreenGrabber();
		imageToMovie.setFrameRate(1000);
		imageToMovie.setHeight(768);
		imageToMovie.setWidth(1024);
		imageToMovie.setContentDescriptor(new ContentDescriptor(
				FileTypeDescriptor.MSVIDEO));
		imageToMovie
				.setOutputMediaLocator(new MediaLocator("/home/iaarc/teste.avi"));
		DataSource ds = null;
		//try {
			ds = imageToMovie.captureScreen();
		//} catch (CannotCaptureScreenException e) {
		//	e.printStackTrace();
		//}
    	np.setDataSource(ds);
    	this.arCoLIVEPlayerInternalFrame1.setArcolivePlayer(np);
    	try {
			this.arCoLIVEPlayerInternalFrame1.playLocalMedia();
		} catch (CannotPlayStreamException e) {
			e.printStackTrace();
		}
//    	try {
//    		MediaRecorder mr = new MediaRecorder();
//    		mr.setDatasource(ds);
//    		mr.setFormat(new Format[]{new VideoFormat(VideoFormat.CINEPAK)});
//            FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.QUICKTIME);
//            mr.setOutputType(outputType);
//            mr.setTarget(new MediaLocator("file:c:/teste.mov"));
//            mr.record(5000);
//            mr.closeRecorder();
//			ArCoLIVENetworkPlayer p = new ArCoLIVENetworkPlayer();
//			p.setDataSource(ds);
//			ArCoLIVEPlayerInternalFrame alpif = new ArCoLIVEPlayerInternalFrame();
//    		alpif.setArcolivePlayer(p);
//    		alpif.playLocalMedia();
//    	} catch (IOException e) {
//			e.printStackTrace();
//		} catch (CannotPlayStreamException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (CannotRecordMediaException e) {
//			e.printStackTrace();
//		} catch (CannotStopRecorderException e) {
//			e.printStackTrace();
//		}
		
		
    	//CaptureFrame cf = new CaptureFrame("teste");
    	//cf.FrameTransmit(ls);
    	
    	/*try{
            /*arCoLIVEPlayerInternalFrame1.setMediaLocator(new MediaLocator("vfw://0"));
        	arCoLIVEPlayerInternalFrame1.setMediaLocator(new MediaLocator("file:c:/a.mpg"));
            arCoLIVEPlayerInternalFrame1.setVideoFormatType(VideoFormat.H263_RTP);
            String host = "192.168.7.55";
            arCoLIVEPlayerInternalFrame1.setReceptorHost(host);
            arCoLIVEPlayerInternalFrame1.transmitMedia();
            arCoLIVEPlayerInternalFrame1.setReceptionPort(40020);
            arCoLIVEPlayerInternalFrame1.playRemoteMedia();
            arCoLIVERecordMedia1.setSourcePath("vfw://0");
            arCoLIVERecordMedia1.setTarget("file:c:/teste.mov");
            arCoLIVERecordMedia1.setFormat(new Format[]{new VideoFormat(VideoFormat.CINEPAK)});
            FileTypeDescriptor outputType =
 	     new FileTypeDescriptor(FileTypeDescriptor.QUICKTIME);
            arCoLIVERecordMedia1.setOutputType(outputType);
            arCoLIVERecordMedia1.createRecordMedia();
            arCoLIVERecordMedia1.write(5000);
            arCoLIVERecordMedia1.closeWriter();
        } catch(Exception e) {
            e.printStackTrace();
        }*/
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ArCoLIVEApplication ala = new ArCoLIVEApplication();
                ala.setSize(640, 480);
                ala.setVisible(true);
                ala.play();
            }
        });
    }
    
    
}